package com.zw.design.pattern.creational.singleton.hungry;

import java.io.Serializable;

/***
 * 饿汉式
 */
public class HungryLazySingleton implements Serializable {

    private  final  static HungryLazySingleton hungryLazySingleton;
    static {
        hungryLazySingleton =new HungryLazySingleton();
    }
    private HungryLazySingleton(){

    }
    public static HungryLazySingleton getInstance(){
        return hungryLazySingleton;
    }

    /***
     * 写了该方法 那么内部源代码就不会反射的去创建对象 而是之间返回该创建好的对象
     * @return
     */
    private Object readResolve(){
        return hungryLazySingleton;
    }



}
